package layeredcontent.domains.site.views
{
	import flash.events.Event;
	
	import mx.containers.ViewStack;
	import mx.events.ChildExistenceChangedEvent;
	import mx.events.FlexEvent;

	public class BrowserStack extends ViewStack
	{
		private var _numChildren:uint;
		
		public function BrowserStack()
		{
			super();
			addEventListener(ChildExistenceChangedEvent.CHILD_ADD, childAddHandler);
			addEventListener(ChildExistenceChangedEvent.CHILD_REMOVE, childRemoveHandler);
			addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
		}
		
		
		[Bindable("numChildrenChange")]
		public override function get numChildren():int
		{
			return super.numChildren;
		}
		
		
		private function childAddHandler(event:ChildExistenceChangedEvent):void
		{
			if (_numChildren != super.numChildren) {
				_numChildren = super.numChildren;
				dispatchEvent(new Event("numChildrenChange"));
			}
		}
		
		private function childRemoveHandler(event:ChildExistenceChangedEvent):void
		{
			if (_numChildren != super.numChildren) {
				_numChildren = super.numChildren;
				dispatchEvent(new Event("numChildrenChange"));
			}
		}
		
		private function creationCompleteHandler(event:Event):void
		{
			dispatchEvent(new Event("valueCommit"));
		}
	}
}